#include "King.h"

using namespace Rorn::Chess::TheCorruptRook;

King::King(void)
{
}

King::~King(void)
{
}

/*static*/ double King::CalculateScore(const Position& position, Player::Type player, const Square& square)
{
	return 100000;
}

/*static*/ void King::GetLegalMoves(const Position& position, Player::Type player, const Square& startSquare, std::vector<MoveTreeNode>& legalMoves, int depth)
{
	Square squareN(startSquare.GetRank() + 1, startSquare.GetFile());
	if( Square::IsOnBoard(squareN) &&
		(position.GetPiece(player, squareN) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareN));
	}

	Square squareNE(startSquare.GetRank() + 1, startSquare.GetFile() + 1);
	if( Square::IsOnBoard(squareNE) &&
		(position.GetPiece(player, squareNE) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareNE));
	}

	Square squareE(startSquare.GetRank(), startSquare.GetFile() + 1);
	if( Square::IsOnBoard(squareE) &&
		(position.GetPiece(player, squareE) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareE));
	}

	Square squareSE(startSquare.GetRank() - 1, startSquare.GetFile() + 1);
	if( Square::IsOnBoard(squareSE) &&
		(position.GetPiece(player, squareSE) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareSE));
	}

	Square squareS(startSquare.GetRank() - 1, startSquare.GetFile());
	if( Square::IsOnBoard(squareS) &&
		(position.GetPiece(player, squareS) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareS));
	}

	Square squareSW(startSquare.GetRank() - 1, startSquare.GetFile() - 1);
	if( Square::IsOnBoard(squareSW) &&
		(position.GetPiece(player, squareSW) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareSW));
	}

	Square squareW(startSquare.GetRank(), startSquare.GetFile() - 1);
	if( Square::IsOnBoard(squareW) &&
		(position.GetPiece(player, squareW) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareW));
	}

	Square squareNW(startSquare.GetRank() + 1, startSquare.GetFile() - 1);
	if( Square::IsOnBoard(squareNW) &&
		(position.GetPiece(player, squareNW) <= 0) )
	{
		legalMoves.emplace_back(MoveTreeNode(position, Player::GetOpposite(player), depth, startSquare, squareNW));
	}
}